#include <iostream>
using namespace std;

// 命名空间
// 缺省参数
// 函数重载
// 引用

int a = 100;
int b = 200;

namespace self
{
    int a = 10;
    int b = 20;
}

// 带有缺省参数的函数
void Print(int a = 999, int b = 9999999)
{
    cout << a << ' ' << b << endl;
}

void test1()
{
    cout << "命名空间和域的测试" << endl;
    int a = 3, b = 5;
    cout << a << ' ' << b << endl;
    cout << ::a << ' ' << ::b << endl;
    cout << self::a << ' ' << self::b << endl;
    cout << "命名空间和域的测试" << endl;
}

void test2()
{
    cout << "缺省参数测试" << endl;
    Print();
    Print(5);
    Print(5, 55);
    cout << "缺省参数测试" << endl;
}

// 函数重载

int add(int a, int b)
{
    return a + b;
}

double add(double a, double b)
{
    return a + b;
}

void test3()
{
    cout << "函数重载测试" << endl;
    cout << add(::a, ::b) << endl;
    double a = 5.2, b = 13.14;
    cout << add(a, b) << endl;
    cout << "函数重载测试" << endl;
}

// 引用
void swap(int& a, int& b)
{
    int tmp = a;
    a = b;
    b = tmp;
}

void test4()
{
    cout << "引用测试" << endl;
    int a = 0;
    int& b = a;
    int& c = b;
    int& d = a;
    cout << a << endl;
    b ++ ;
    cout << a << endl;
    c ++ ;
    cout << a << endl;
    d ++ ;
    cout << a << endl;
    cout << "-------------------------" << endl;
    
    int n = 66, m = 88;
    cout << n << ' ' << m << endl;
    swap(n, m);
    cout << n << ' ' << m << endl;

    cout << "引用测试" << endl;
}

int main()
{
    test1();
    test2();
    test3();
    test4();

    return 0;
}
